package cp.remote.activity;

import cp.remote.R;
import cp.remote.timer.LoadTimer;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class Load_Activity extends Activity {

    private EditText progr;
    private Button config;
    private Activitys act;
    private Bundle extras;
    private Intent actconfig;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.load);
        extras = getIntent().getExtras();
        progr = (EditText) findViewById(R.id.load_text);
        config = (Button) findViewById(R.id.load_cmbconfig);
        act = (Activitys) extras.getSerializable("Activity");
        
        this.config.setOnClickListener(new OnClickListener() {
            
            public void onClick(View v) {
                startActivity(actconfig);
                finish();
            }
        });
    }

    @Override
    public void onStart() {
        super.onStart();
        actconfig = new Intent(this, Config_Activity.class);
        Handler myHandler = new Handler();
        LoadTimer t = new LoadTimer(this, extras.getString("Command"),
                myHandler);
        myHandler.removeCallbacks(t);
        myHandler.postDelayed(t, 100);
    }

    public void finishLoadingTheActivity() {
        Intent i;
        switch (act) {
        case BARRIER:
            i = new Intent(this, BarrierAvoiding_Activity.class);
            break;
        case REMOTE:
            i = new Intent(this, Remote_Activity.class);
            break;
        case PEOPLE:
            i = new Intent(this, PeopleTracking_Activity.class);
            break;
        default:
            return;
        }
        startActivity(i);
        finish();
    }

    public void cancelLoadingTheActivity() {
        progr.append("Loading Canceled\n");
        config.setVisibility(View.VISIBLE);
    }

    public void setProgressText(String txt) {
        progr.append(txt + "\n");
    }

}
